import java.util.concurrent.TimeUnit;

public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        //打印所有的线程状态
        //printState();
        Thread t1=new Thread(()->{
            System.out.println("当前线程状态2:"+Thread.currentThread().getState());
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println("当前线程的状态1:"+t1.getState());
        t1.start();
        //让主线程休眠1s
        Thread.sleep(1000);
        System.out.println("当前线程的状态3:"+t1.getState());

        //等待子线程执行完
        t1.join();
        System.out.println("打印线程状态4:"+t1.getState());

    }

    private static void printState() {
        for(Thread.State item:Thread.State.values()) {
            System.out.println(item);
        }
    }
}
